<template>
  <div class="page-main gasStationReview">
    <CustomForm :formInline="formInline" @onSubmit="onSubmit" @resetTable="resetTable">
      <el-form-item label="加油站名称">
        <el-input v-model="formInline.name" placeholder="输入公司名称"></el-input>
      </el-form-item>
      <el-form-item label="法人名称">
        <el-input v-model="formInline.user_name" placeholder="输入账号"></el-input>
      </el-form-item>
      <el-form-item label="审核状态">
        <el-select v-model="formInline.status" placeholder="选择审核状态" @change="initial">
          <el-option label="全部" value="-1"></el-option>
          <el-option label="待审核" value="0"></el-option>
          <el-option label="审核通过" value="1"></el-option>
          <el-option label="审核失败" value="2"></el-option>
          <el-option label="审核通过.加油站关闭" value="3"></el-option>
        </el-select>
      </el-form-item>

      <!-- <el-form-item label="所属地区">
        <el-select v-model="formInline.area_status" placeholder="选择所属公司" @change="selectArea">
          <el-option label="全部" :value="-1"></el-option>
          <el-option
            v-for="(item, index) in getOfficesList"
            :key="item"
            :label="item"
            :value="index"
          ></el-option>
        </el-select>
      </el-form-item>-->
    </CustomForm>

    <!-- <CustomDescriptions :data="descriptionsData" :styleBox="{ width: '100%' }"></CustomDescriptions> -->

    <el-table :data="list" style="width: 100%" height="680" align="center" v-loading="tableLoading">
      <el-table-column
        prop="name"
        label="加油站名称"
        width="250"
        align="center"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column prop="user_name" label="法人名称" width="100" align="center">
        <template slot-scope="scope">
            {{ $maskString(scope.row.user_name) }}
        </template> 
        
      </el-table-column>
      <el-table-column prop="id_num" label="法人身份证号" align="center">
        <template slot-scope="scope">
            {{ $maskString(scope.row.id_num) }}
        </template> 
      </el-table-column>
      <el-table-column
        prop="address"
        label="地址"
        width="250"
        align="center"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column prop="status" label="审核状态" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.status == 0" style="color: red;">未审核</span>
          <span v-if="scope.row.status == 2" style="color: red;">未通过</span>
          <span v-if="scope.row.status == 1" style="color: green;">通过</span>
          <span v-if="scope.row.status == 3" style="color: green;">
            通过.
            <span style="color: red;">加油站未开启</span>
          </span>
        </template>
      </el-table-column>
      <el-table-column prop="status" label="开关状态" align="center">
        <template slot-scope="scope">
          <el-switch
            :value="scope.row.status"
            :disabled="scope.row.status == 2 || scope.row.status == 0"
            v-loading="switchLoading"
            @change="(val) => switchStatus(val, scope.row.id,scope.row)"
            :active-value="1"
            :inactive-value="scope.row.status == 2 ? 2 : 3"
            active-color="#13ce66"
            inactive-color="#ff4949"
          ></el-switch>
        </template>
      </el-table-column>
      <el-table-column
        prop="add_time"
        label="提交时间"
        width="150"
        align="center"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column prop="address" label="操作" align="center">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="primary"
            v-if="scope.row.status == 0"
            @click="action('review',scope.row)"
          >审核</el-button>
          <el-button
            size="mini"
            type="primary"
            v-if="scope.row.status != 0"
            @click="action('check',scope.row)"
          >查看</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page.sync="formInline.page"
      :page-sizes="$pageSizeList"
      :page-size="formInline.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    ></el-pagination>

    <el-dialog :title="config.status == 2 ? '加油站审核' :'加油站查看'" top="5vh" :visible.sync="dialogVisible" width="60%">
      <reviewDialog v-if="dialogVisible" :form="config" @refresh="initial"></reviewDialog>
    </el-dialog>
  </div>
</template>

<script>

import { getOilList, reviewGasStationsStatus } from "@/api/gasStation";
import reviewDialog from "./components/reviewDialog";
export default {
  components: {
    reviewDialog
  },
  name: "gasStationReview",
  data() {
    return {
      config: {},
      formInline: {
        name: "",
        user_name: "",
        status: "-1",
        page: 1,
        pageSize: 10
      },
      switchLoading: false,
      tableLoading: true,
      list: [],
      total: 0,
      dialogVisible: false
    };
  },
  mounted() {
    this.initial();
  },
  methods: {
    async initial() {
      this.dialogVisible = false;
      this.tableLoading = true;
      let result = await getOilList(this.formInline);
      if (result.code == 200) {
        this.tableLoading = false;
        this.list = result.data.data;
        this.total = result.data.total;
      }
    },
    onSubmit(data) {
      this.page = 1;
      this.initial();
    },
    resetTable() {
      this.formInline = {
        name: "",
        user_name: "",
        status: "-1",
        page: 1,
        pageSize: 10
      };
      this.formInline.page = 1;
      this.formInline.pageSize = 10;
      this.initial();
    },
    handleSizeChange(pageSize) {
      this.formInline.pageSize = pageSize;
      this.formInline.page = 1;
      this.initial();
    },
    handleCurrentChange(page) {
      this.formInline.page = page;
      this.initial();
    },
    async switchStatus(val, id,row) {
      this.switchLoading = true;
      let res = await reviewGasStationsStatus({
        id,
        status: val
      });
      this.switchLoading = false;
      if (res.code === 200) {
        row.status = val;
        this.$message.success("修改状态成功");
      } else {
        this.$message.error(res.msg);
      }
    },
    action(type, row) {
      this.dialogVisible = true;
      this.config = row;
    }
  }
};
</script>

<style lang="scss" scoped>
.gasStationReview {
}
</style>
